home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Think Class Libraries / CChoreQuartet 1.0.1 / CCommanderChore.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-30  |  2.2 KB  |  113 lines  |  [TEXT/KAHL]

  1. /*
  2.  * CCommanderChore.c
  3.  *
  4.  * A chore that sends a command.
  5.  *
  6.  * There are three ways to send the command:  once with an urgent
  7.  * chore, once with an idle chore, or continuously with an idle
  8.  * chore.  I advise using the functions doCommandViaUrgentChore(),
  9.  * doCommandViaIdleChore(), and doCommandContinuouslyViaIdleChore();
  10.  * they'll do all the setting-up for you.  The latter returns the
  11.  * chore in question, so that if you want to cancel it later,
  12.  * you can.  The former two cancel themselves, so you don't need
  13.  * to worry about them.
  14.  *
  15.  * © Copyright 1992-93 by Jamie R. McCarthy.  All rights reserved.
  16.  * This code can be both distributed and used freely.
  17.  * Internet: k044477@kzoo.edu            AppleLink: j.mccarthy
  18.  *
  19.  */
  20.  
  21.  
  22.  
  23. /********************************/
  24.  
  25. #include "CCommanderChore.h"
  26.  
  27. /********************************/
  28.  
  29.  
  30.  
  31. void doCommandViaIdleChore(long theCommand)
  32. {
  33.     CCommanderChore *theChore;
  34.     theChore = new(CCommanderChore);
  35.     theChore->setCommand(theCommand);
  36.     theChore->setUrgent(FALSE);
  37.     theChore->setSendsContinuously(FALSE);
  38.     gApplication->AssignIdleChore(theChore);
  39. }
  40.  
  41.  
  42.  
  43. CCommanderChore *doCommandContinuouslyViaIdleChore(long theCommand)
  44. {
  45.     CCommanderChore *theChore;
  46.     theChore = new(CCommanderChore);
  47.     theChore->setCommand(theCommand);
  48.     theChore->setUrgent(FALSE);
  49.     theChore->setSendsContinuously(TRUE);
  50.     gApplication->AssignIdleChore(theChore);
  51. }
  52.  
  53.  
  54.  
  55. void doCommandViaUrgentChore(long theCommand)
  56. {
  57.     CCommanderChore *theChore;
  58.     theChore = new(CCommanderChore);
  59.     theChore->setCommand(theCommand);
  60.     theChore->setUrgent(TRUE);
  61.     gApplication->AssignUrgentChore(theChore);
  62. }
  63.  
  64.  
  65.  
  66. void CCommanderChore::Perform(long *maxSleep)
  67. {
  68.     if (!reallyPerform()) return;
  69.     
  70.     TRY {
  71.         gGopher->DoCommand(itsCommand);
  72.     } CATCH {
  73.             /*
  74.              * If some kind of error occurred, forget about doing
  75.              * this command again.
  76.              */
  77.         cancelSelf();
  78.     } ENDTRY;
  79.     
  80.     if (!sendsContinuously) {
  81.         itsCommand = cmdNull;
  82.         cancelSelf();
  83.     }
  84. }
  85.  
  86.  
  87.  
  88. void CCommanderChore::setCommand(long theCommand)
  89. {
  90.     itsCommand = theCommand;
  91. }
  92.  
  93.  
  94.  
  95. long CCommanderChore::getCommand(void)
  96. {
  97.     return itsCommand;
  98. }
  99.  
  100.  
  101.  
  102. void CCommanderChore::setSendsContinuously(Boolean theSendsContinuously)
  103. {
  104.     sendsContinuously = (theSendsContinuously != FALSE);
  105. }
  106.  
  107.  
  108.  
  109. Boolean CCommanderChore::getSendsContinuously(void)
  110. {
  111.     return sendsContinuously;
  112. }
  113.